#!/bin/bash
#./BitteGerneRun.sh cwd tmplFile SECONDS opTarFile
#  cwd --- directory where the BitteGerneScript can be found
#  tmpl --- template file
#  SECONDS -- time taken till the invocation of this script
#  opTarFile --- tared and zipped file where the generated code is to be stored
<#--  Generate BitterGerne script with rep/Replacement strings -->
<#include "/@inc/funcMacros.ftl"> 
<#assign className = TriaGram + "E" + Prefix + LateType>
<#assign intfName = TriaGram + "I" + Prefix + LateType>

# remove all the interfaces that are not required
<#list Interfaces as intf>
<#if  intf.req == "n" >
find . -name "*${intf.postFix}" | xargs rm -f
</#if>
</#list>

# Remove the test CATPart/ CATFct
find NEOForayWS -name "*.CATfct" | xargs rm -f

$1/BitteGerne.sh NEOForayWS ${Workspace} NEO ${TriaGram} Pix ${Prefix} Template ${AppName} Feature ${LateType}  "${TriaGram}.*[IE]\?[A]\?Utl" ${TriaGram}${Prefix}

# Copy Initial Template to Output Dir --- for future reference
if [ -f $2 ] ; then
	cp $2 ${Workspace}/Template_${LateType}.py
else
	cp $1/$2 ${Workspace}/Template_${LateType}.py
fi

let "timeTaken=$3 + $SECONDS"
echo "Total Time Taken" $timeTaken "seconds"

#cd ${Workspace}
# Run the mkErr Script to check the code quality
#mkErr ws sm

# Compute the number of lines
find ${Workspace} -type f | xargs wc -l | sort > ${Workspace}/${Workspace}.stats.txt

# Zip the generated workspace - quietly
tar -zcf  ${Workspace}.tar.gz ${Workspace}
# Copy/Move it to desired file name
if [ -n "$5" ] ; then
	cp -f ${Workspace}.tar.gz $5 
	cp ${Workspace}/${Workspace}.stats.txt `dirname $5`		# Copy the file statistic to the original directory
fi

#Start Visual Studio
#"/cygdrive/d/ProgramFiles/Microsoft Visual Studio 8/./Common7/IDE/devenv.exe" &
#cygstart "/cygdrive/d/ProgramFiles/Microsoft Visual Studio 8/./Common7/IDE/devenv.exe"
#cmd /c " D:\ProgramFiles\AutoIt3\autoit3.exe "E:\raman\UNIX\codepattern\MultyiOptionWS.au3""

# Build the CAA workspace and launch CATIA
# pass the workspace and the catalog name to generate, for datum catalog.name can be empty.
openCatia=$4
echo "Open in CATIA option " $openCatia
if [ -n "$4" ] ; then
if [ $4 -gt 0 ] ; then
	cmd /c "E:\raman\UNIX\codepattern\TemplateWS.bat ${Workspace} ${Catalog.name}"
fi
fi
